﻿using System.Linq;
using Castle.DynamicProxy;
using Crow.Library.DatabaseLayer;
using Crow.Library.DatabaseLayer.DataAttributes;

namespace Crow.Library.Interceptors.DatabaseInceptors.DbOperations
{
    internal class DeleteOperator : DbOperationBase
    {
        public override void Execute(IInvocation invocation, DbAttributeBase attribute)
        {
            Database db = DatabaseHelper.GetDatabase();
            db.Connection.Open();
            try
            {
                int result = db.Delete(invocation.Arguments.FirstOrDefault());
                SetInvocationResult(invocation, result);
            }
            finally
            {
                db.Connection.Close();
            }
        }
    }
}